package A_review.review5_8;

public class LongestPalindrome {

    public String longestPalindrome(String s) {
        String res="";
        if (s.length()==0){
            return res;
        }
        for (int i = 0; i <s.length() ; i++) {
            String s1 = judgePalindrome(s, i, i);
            String s2 = judgePalindrome(s, i, i + 1);
            res=res.length()>s1.length()? res:s1;
            res=res.length()>s2.length()?res:s2;
        }
        return  res;
    }

    //  CKG TODO 2023/5/8: 从中间向两边扩散
    public  String judgePalindrome(String s,int left,int right){
        //  CKG TODO 2023/5/8:  格式错误
        while (left>=0&&right<s.length()&&s.charAt(left)==s.charAt(right)){
          left--;
          right++;
        }
        return s.substring(left+1,right);
    }

    public static void main(String[] args) {
        LongestPalindrome longestPalindrome = new LongestPalindrome();
        System.out.println(longestPalindrome.longestPalindrome("sbbb"));
    }


}
